package com.mxy.batterychargingreminding;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

/**
 * 电池变更广播接收器
 *
 * @author 马晓勇
 */

public class PhoneBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            Intent myservice = new Intent(context, MyService.class);
            //Android 8.0开始ACTION_BOOT_COMPLETED广播接收后，不能直接startService，因为此时Android系统判定你的应用程序为后台进程
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                context.startForegroundService(myservice);
            } else {
                context.startService(myservice);
            }
        }
    }
}